<?php


namespace app\api\community\utils;


class basicUtils
{

    /**
     * 短链生成
     * @param string $url
     * @return string
     */
    public function shortUrl(string $url): string {
        $short = '';
        $shortCrcCode = sprintf('%u', crc32($url));
        while ($shortCrcCode > 0) {
            $str = $shortCrcCode % 62;
            if ($str > 35) {
                $str = chr($str + 61);
            } else if ($str > 9 && $str <= 35) {
                $str = chr($str + 55);
            }
            $short .= $str;
            $shortCrcCode = floor($shortCrcCode / 62);
        }
        return $short;
    }

}